// 批量更新图片路径脚本 - 将.jpg改为.svg
const fs = require('fs');

console.log('🔄 开始批量更新图片路径...\n');

const filesToUpdate = [
    'js/extendedStory.js',
    'js/gameEngine.js', 
    'js/endingsManager.js',
    'js/imagePreloader.js',
    'js/main.js',
    'js/megaStoryExpansion.js'
];

let totalReplacements = 0;

filesToUpdate.forEach(filePath => {
    if (fs.existsSync(filePath)) {
        console.log(`📝 处理文件: ${filePath}`);
        
        let content = fs.readFileSync(filePath, 'utf8');
        let originalContent = content;
        
        // 将所有 images/xxx.jpg 替换为 images/xxx.svg
        content = content.replace(/images\/([^"'\s]+)\.jpg/g, 'images/$1.svg');
        
        if (content !== originalContent) {
            fs.writeFileSync(filePath, content, 'utf8');
            
            // 计算替换次数
            const matches = originalContent.match(/images\/[^"'\s]+\.jpg/g);
            const replacements = matches ? matches.length : 0;
            totalReplacements += replacements;
            
            console.log(`   ✓ 已更新 ${replacements} 个图片路径`);
        } else {
            console.log(`   - 无需更新`);
        }
    } else {
        console.log(`   ✗ 文件不存在: ${filePath}`);
    }
});

console.log(`\n🎉 完成！总共更新了 ${totalReplacements} 个图片路径`);
console.log(`📸 所有图片现在都将加载SVG占位符`);
console.log(`🚀 游戏图片加载问题已解决！`);